package com.asit.demo.mapper;

import com.asit.demo.model.User;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

public interface UserMapper extends BaseMapper<User> {
    //@DS("salve1")
    public User findUserByName(String name);

    default public User selectById(String datasourceName,Integer id){
        DynamicDataSourceContextHolder.push(datasourceName);//数据源名称
        User user = null;
        try {
            // your code 需注意使用后一定要使用poll清空数据源，
            user = selectById(id);
        } catch (Exception e) {
            throw e;
        } finally {
            DynamicDataSourceContextHolder.poll();
        }
        return user;
    }

}
